package app.imttf.offline.backing.buatttf;

import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import javax.servlet.http.HttpServletRequest;

import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

public class ScanActionDocCapture {
    private String url;

    public ScanActionDocCapture() {
    }

    public void ScanBpbPkp(ActionEvent actionEvent) {
        // Scan BPB PKP calling Oracle Doc Capture
        System.out.println("Scan BPB PKP");

        StringBuilder script = new StringBuilder();
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request =
            (HttpServletRequest)context.getCurrentInstance().getExternalContext().getRequest();

        url =
"window.open(\"http://192.168.0.103:16400/dc-client/faces/dc-client?CaptureWorkspace=TesTTF&ClientProfile=Scan%20BPB&CaptureDriver=CAPTURE_TWAIN_DRIVER&CaptureSource=Canon%20DR-M140%20TWAIN&SignOutOnRelease=1&SignOutAction=CloseBrowser&ShowAllBatches=0\");";

        script.append(url);
        ExtendedRenderKitService erks =
            Service.getService(context.getRenderKit(),
                               ExtendedRenderKitService.class);
        erks.addScript(context, script.toString());
    }

    public void ScanFakturPkp(ActionEvent actionEvent) {
        // Scan Faktur PKP calling Oracle Doc Capture
        System.out.println("Scan Faktur PKP");

        StringBuilder script = new StringBuilder();
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request =
            (HttpServletRequest)context.getCurrentInstance().getExternalContext().getRequest();

        url =
"window.open(\"http://192.168.0.103:16400/dc-client/faces/dc-client?CaptureWorkspace=TesTTF&ClientProfile=Scan%20BPB&CaptureDriver=CAPTURE_TWAIN_DRIVER&CaptureSource=Canon%20DR-M140%20TWAIN&SignOutOnRelease=1&SignOutAction=CloseBrowser&ShowAllBatches=0\");";

        script.append(url);
        ExtendedRenderKitService erks =
            Service.getService(context.getRenderKit(),
                               ExtendedRenderKitService.class);
        erks.addScript(context, script.toString());
    }

    public void ScanBpbNonPkp(ActionEvent actionEvent) {
        // Scan BPB Non PKP calling Oracle Doc Capture
        System.out.println("Scan BPB Non PKP");

        StringBuilder script = new StringBuilder();
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request =
            (HttpServletRequest)context.getCurrentInstance().getExternalContext().getRequest();

        url =
"window.open(\"http://192.168.0.103:16400/dc-client/faces/dc-client?CaptureWorkspace=TesTTF&ClientProfile=Scan%20BPB&CaptureDriver=CAPTURE_TWAIN_DRIVER&CaptureSource=Canon%20DR-M140%20TWAIN&SignOutOnRelease=1&SignOutAction=CloseBrowser&ShowAllBatches=0\");";

        script.append(url);
        ExtendedRenderKitService erks =
            Service.getService(context.getRenderKit(),
                               ExtendedRenderKitService.class);
        erks.addScript(context, script.toString());
    }

    public void ScanFakturNonPkp(ActionEvent actionEvent) {
        // Scan Faktur Non PKP calling Oracle Doc Capture
        System.out.println("Scan Faktur Non PKP");

        StringBuilder script = new StringBuilder();
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request =
            (HttpServletRequest)context.getCurrentInstance().getExternalContext().getRequest();

        url =
"window.open(\"http://192.168.0.103:16400/dc-client/faces/dc-client?CaptureWorkspace=TesTTF&ClientProfile=Scan%20BPB&CaptureDriver=CAPTURE_IMPORT_DRIVER&CaptureSource=Import%20Source&SignOutOnRelease=1&SignOutAction=CloseBrowser\");";

        script.append(url);
        ExtendedRenderKitService erks =
            Service.getService(context.getRenderKit(),
                               ExtendedRenderKitService.class);
        erks.addScript(context, script.toString());
    }
}
